package com.czzapp.xiaoyumemo.service;

import java.io.File;
import java.util.List;

import com.czzapp.xiaoyumemo.model.Memo;
import com.czzapp.xiaoyumemo.model.MemoManager;
import com.czzapp.xiaoyumemo.model.SdStatus;
import com.czzapp.xiaoyumemo.model.SdStatusManager;
import com.czzapp.xiaoyumemo.util.MemoNoticeUtil;

import android.app.Service;
import android.content.Intent;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.widget.Toast;

//开机启动
public class StartupService extends Service {
	Handler mHandler = new Handler();
	@Override
	public IBinder onBind(Intent arg0) {
		return null;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		Thread runningThread = new Thread(new Runnable() {

			@Override
			public void run() {
				SdStatusManager.getInstance().setSdStatus(SdStatus.Umounted);
				while (Environment.getExternalStorageState().compareTo(Environment.MEDIA_MOUNTED) != 0) {
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				SdStatusManager.getInstance().setSdStatus(SdStatus.Preparing);
				File sdFile = Environment.getExternalStorageDirectory();
				while (!sdFile.canWrite()) {
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				init();
				SdStatusManager.getInstance().setSdStatus(SdStatus.Ready);
			}
		});
		runningThread.start();
	}
	
	@Override
	public void onDestroy() {
		super.onDestroy();
		destroy();
	}
	
	//.加载资源模块
	//.注册memo content的观察者
	//.将过期未check的memo放到提醒栏里
	private void init() {
		MemoManager.init(this);
	}
	
	private void destroy() {
	}
}
